package com.endbd.marketing.control;


import com.endbd.feignapi.model.marketing.Orderdetails;
import com.endbd.marketing.model.MarketingOrdersCondition;
import com.endbd.marketing.model.MarketingOrdersDetailsCondition;
import com.endbd.marketing.model.ResultMessage;
import com.endbd.marketing.service.IMarketingService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/marketing")
public class ApiControl {

    @Autowired
    private MarketingControl marketingControl;
    @Autowired
    private IMarketingService marketingService;

    @RequestMapping("/api/queryOrderDetails")
    @ResponseBody
    public List<Orderdetails> getOrderDetails(@RequestParam String orderId) {
        MarketingOrdersDetailsCondition marketingOrdersDetailsCondition = new MarketingOrdersDetailsCondition();
        marketingOrdersDetailsCondition.setOrderId(orderId);
        ResultMessage resultMessage = marketingControl.queryOrderDetailsByOrderId(marketingOrdersDetailsCondition);

        return (List<Orderdetails>) resultMessage.getResultData();
    }

    @RequestMapping("/api/updateOrderForWarehouse")
    @ResponseBody
    public ResultMessage updateOrderForWarehouse(@RequestParam String orderId, @RequestParam Integer warehouseId){
        MarketingOrdersCondition conn = new MarketingOrdersCondition();
        conn.setOrderId(orderId);
        conn.setWarehouseId(warehouseId);
        Integer state2=1;
        conn.setState(state2);
//        marketingService.addOrderWarehouse(conn);
        marketingService.updateOrderWarehouse(conn);
        ResultMessage rm=new ResultMessage();
        rm.setStatus("200");
        rm.setFlag(true);
        rm.setMsg("");
        return rm;
    }
}
